var db=require("../db/db.js");
var express=require("express");
var router=require('vue-router')
var app=express();
var bodyParser=require("body-parser");
const { request, response } = require("express");
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
var router=express.Router();
//new db.Draftbox({username:"boss",title:"12345",description:"456789",date:"2020/9/25-17:22:34"}).save()
// db.Draftbox.find().then(res=>{
//     console.log(res)
// }).catch(err=>{
//     console.log(err)
// })
router.get('/myBlog/draftBox',(request,response)=>{

    db.Draftbox.updateOne({_id:request.query._id},{$set:{title:request.query.title,description:request.query.description,draftContent:request.query.draftContent}}).then((res)=>{
        //console.log(res)
    })
    db.Draftbox.find({username:request.query.username}).then(res=>{
        // console.log("123")
        // console.log(res)
        response.send(res)
    }).catch(err=>{
        console.log(err)
    })
})
router.get("/myBlog/addDr",(request,response)=>{
    new db.Draftbox(request.query).save()
})
router.get("/myBlog/editDraft",(request,response)=>{
    db.Draftbox.find(request.query).then(res=>{
        response.send(res)
        //console.log(res)
    })
})
router.get("/myBlog/deleteDraft",(request,response)=>{
    db.Draftbox.deleteOne(request.query).then(()=>{
        db.Draftbox.find({username:request.query.username}).then(res=>{
           // console.log(res)
            response.send(res)
        })
    })
})
module.exports=router;